package com.health.article.controller;

import com.health.article.domain.dto.ShmArticleDTO;
import com.health.article.domain.vo.ShmSubjectVO;
import com.health.article.service.ArticleService;
import com.health.common.core.domain.R;
import com.health.common.core.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 20250311 云计算-维度健康-01-创作中心V1.1-20250115
 */
@RestController
@RequestMapping("article")
public class ArticleController extends BaseController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("selectArticleAll")
    public R selectArticleAll(){
        return R.ok(articleService.selectArticleAll());
    }

    @PostMapping("/authoringArticles")
    public R authoringArticles(@RequestBody ShmArticleDTO shmArticleDTO){
        articleService.insertArticle(shmArticleDTO);
        return R.ok();
    }

    @GetMapping("/selectMyDraftAndArticle")
    public R selectMyDraftAndArticle(){
        return R.ok(articleService.selectMyDraftAndArticle());
    }

    @GetMapping("/selectSubjectAll")
    public R selectSubjectAll(){
        List<ShmSubjectVO> shmSubjectVOS = articleService.selectSubjectALl();
        return R.ok(shmSubjectVOS);
    }

    @GetMapping("/selectMyArticle/{type}")
    public R selectMyArticle(@PathVariable Long type){
        return R.ok(articleService.selectMyArticle(type));
    }

    @GetMapping("/selectArticleInfo/{id}")
    public R selectArticleInfo(@PathVariable Long id){
        return R.ok(articleService.selectArticleInfo(id));
    }

    @DeleteMapping("/deleteMyDraft/{id}")
    public R deleteMyDraft(@PathVariable Long id){
        articleService.deleteMyDraft(id);
        return R.ok();
    }

    @PutMapping("/editMyDraft")
    public R editMyDraft(@RequestBody ShmArticleDTO shmArticleDTO){
        articleService.editMyDraft(shmArticleDTO);
        return R.ok();
    }

}
